package mof.gov.dmdc.view.exportadapter;

import java.util.ArrayList;
import java.util.List;

import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;

import mof.gov.dmdc.view.common.Common;

import oracle.jbo.Row;
import oracle.jbo.ViewObject;


public class AdvancedExportAdapter extends ExportAdapter{
    public AdvancedExportAdapter() {
        super();
        initTotalList(); //Create total List        
    }

    private List totalList;

    public void setTotalList(List attrList) {
        this.totalList = attrList;
    }

    public List getTotalList() {
        return totalList;
    }

    private void initTotalList() {
        if (totalList == null || totalList.isEmpty()) {
            ViewObject view = getViewObject();
            totalList = new ArrayList();
            do {
                Row row = (view.hasNext()) ? view.next() : view.first();
                String attrName = "";
                String attrType = "";
                String attrLabel = "";
                if (row != null) {
                    try {
                        attrName = row.getAttribute("ColName").toString();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    try {
                        attrLabel = row.getAttribute("LabelDisp").toString();
                    } catch (Exception e) {
                        attrLabel = "";
                    }
                    String totalString = attrName;
                    SelectItem item = new SelectItem(totalString, attrLabel);
                    totalList.add(item);
                }
            } while (view.hasNext());            
        }
    }

    public void refreshModel(ValueChangeEvent valueChangeEvent) {
        Common.refreshComponent(valueChangeEvent.getComponent().getParent());
    }    
}


